package com.yc.game.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.game.cms.dao.TrainingContentMapper;
import com.yc.game.cms.dao.TrainingVoMapper;
import com.yc.game.cms.pojo.TrainingContent;
import com.yc.game.cms.service.TrainingContentService;
import com.yc.game.cms.vo.TrainingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainingContentServiceImpl implements TrainingContentService {
    @Autowired
    private TrainingContentMapper trainingContentMapper;
    @Autowired
    private TrainingVoMapper trainingVoMapper;

    /**
     * 查询所有
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<TrainingContent> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TrainingContent> trainingContents = trainingContentMapper.getAll();
        PageInfo<TrainingContent> pageInfo = new PageInfo<>(trainingContents);
        return pageInfo;
    }

    /**
     * 更新审核状态
     * @param trainingContent
     * @return
     */
    @Override
    public int update(TrainingContent trainingContent) {
        TrainingContent newContent = new TrainingContent();
        newContent.setId(trainingContent.getId());
        newContent.setStatus(trainingContent.getStatus());
        return trainingContentMapper.updateByPrimaryKeySelective(newContent);
    }

    /**
     * 根据id删除
     * @param trainingId
     * @return
     */
    @Override
    public int deleteById(Integer trainingId) {
        return trainingContentMapper.deleteByPrimaryKey(trainingId);
    }

    @Override
    public PageInfo<TrainingVo> findAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TrainingVo> trainingContents = trainingVoMapper.getAll();
        PageInfo<TrainingVo> pageInfo = new PageInfo<>(trainingContents);
        return pageInfo;
    }
}
